<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title></title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css\iconfont\Rjdaoico.css" type="text/css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/message.css">
</head>
<body>
	<div class="messShow">

	</div>
<%--	<a name="footNext"></a>--%>
</body>
<script src="${pageContext.request.contextPath}/js/jquery-3.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
	$(function(){
        userMessage();
	})
	function userMessage() {
		var data = {"message":"${userMessage}"}//消息
		$.ajax({
			url:"${pageContext.request.contextPath}/sendUserMessage",
			method:"POST",
			data:data,
			success:function (data) {//后台返回数据
				console.log(data);
				for (var i=0;i < data.length;i++){
					if (data[i].name == "${sessionScope.user.memberName}"){
						var $div = $('<div class="own"></div>');
						var $head = $('<img src="'+data[i].myimg+'">');
						var $name = $('<div class="user">'+data[i].name+'</div>');
						var $time = $('<div class="sj">'+data[i].mytime+'</div>');
						var $mess = $('<div class="text">'+data[i].message+'</div>');
						$(".messShow").append($div);
						$div.append($head).append($name).append($time).append($mess);
					}else{
						var $div = $('<div class="show"></div>');
						var $head = $('<img src="'+data[i].myimg+'">');
						var $name = $('<div class="user">'+data[i].name+'</div>');
						var $time = $('<div class="sj">'+data[i].mytime+'</div>');
						var $mess = $('<div class="text">'+data[i].message+'</div>');
						$(".messShow").append($div);
						$div.append($head).append($name).append($time).append($mess);
					}
				}
			}
		});
	}
	// var ds = setInterval("loading()",1000);

	// function loading(){
	// 	userMessage();
	// 	location.href="#footNext";
	// }

	// $(function(){
	// 	$("messShow").hover(function() {
	// 		clearInterval(ds);
	// 	}, function() {
	// 		ds = setInterval("loading()",1000);
	// 	});
	// })
 </script>
</html>